\fi-440\li440 Q: The documentation for the NXImage method
\b initFromFile:
\b0 says:\
\fi0\li0 \
\pard\tx360\tx880\tx3440\tx4600\tx5760\tx6900\tx8060\tx9200\tx10360\tx11520\fi20\li1360 After finishing the initialization, this method returns
\b self
\b0 . However, if the new instance can't be initialized, it is freed and
\b nil
\b0 is returned.\
\pard\tx3120\tx3620\tx4120\li2620 \
\pard\tx960\tx1920\tx2880\tx3840\tx4800\tx5760\tx6720\tx7680\tx8640\tx9600\li400 In my application, nil is never returned, even if I read in a bogus file. Is this a bug? Here is my code:\
\
\f2\fs24\fi1040 id myNXImage = [NXImage alloc];\
if ([myNXImage initFromFile: "dummyName.tiff"] == nil)\
\fi-440\li440 A: This is not a bug although the documentation could be clearer. The
\b initFromFile:
\b0 method is lazy and will not catch
\i all
\i0 the errors that might happen when loading an image. Your application should be prepared to check for errors later on down the line either through delegation or by checking the
\b composite:
\b0 or
\b lockFocus
\b0 return values. If you wish, you can force the image to be rendered immediately:\
\fi0\li0 \
\f2\fs24\fi1040\li400 id myNXImage = [[NXImage alloc] initFromFile: filename];\
if ([myNXImage lockFocus])\
[image unlockFocus];\
else\
fprintf(stderr,"%s doesn't exist\\n", filename);\
\
\
\f1\fs28\fi0 Although this behavior might seem confusing it allows for more optimal performance: the image isn't rendered into the cache until it is needed. Rendering a large or complex file can be slow—particularly for a complex EPS file.\
\
\b Note:
\b0 Another good approach for determining whether an image can be successfully rendered is the NXImage delegate method
\b imageDidNotDraw:inRect:
\b0 . If you have assigned a delegate for the image and implemented this method, it gets called when compositing fails for whatever reason. See the documentation on NXImage for more information about this method. Also note that this method of delegation may be the only way to catch a drawing error for an image which is being "handed" to the AppKit—an icon on a button, for example.\
\
There is a known bug in Release 2 where
\b imageDidNotDraw:inRect:
\b0 fails to be called when encountering an error from within the method
\b composite:toPoint:
\b0 . This bug can be avoided by using the NXImage method